package com.mvc.base.model;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.mvc.framework.model.CompositeKeyAuditableEntity;

/**
 * 
 * @author snowpbx
 * @version V1.0 Create Time: 2012-10-25
 */
@Entity(name = "B_PICTURE")
@IdClass(PicturePK.class)
public class Picture extends CompositeKeyAuditableEntity {
	public static final int	PICTURE_OF_SAMPLE	 = 1;
	public static final int	PICTURE_OF_ORDER	 = 2;
	public static final int	PICTURE_OF_PURCHASE	 = 3;
	public static final int	PICTURE_OF_QUOTATION	= 4;

	@Id
	private Integer	        itemId;
	@Id
	private Integer	        type;
	@Id
	private Long	        fileId;
	@Length(max = 128)
	@NotNull
	private String	        fileName;
	@Length(max = 64)
	private String	        remark;

	public Integer getItemId() {
		return itemId;
	}

	public void setItemId(Integer itemId) {
		this.itemId = itemId;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public Long getFileId() {
		return fileId;
	}

	public void setFileId(Long fileId) {
		this.fileId = fileId;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Transient
	public String getFileSuffix() {
		if (fileName != null) {
			return fileName.substring(fileName.indexOf("."));
		}
		return "";
	}

}

class PicturePK implements Serializable {
	private Integer	itemId;
	private Integer	type;
	private Long	fileId;

	public Integer getItemId() {
		return itemId;
	}

	public void setItemId(Integer itemId) {
		this.itemId = itemId;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public Long getFileId() {
		return fileId;
	}

	public void setFileId(Long fileId) {
		this.fileId = fileId;
	}

}
